import {observable, action} from 'mobx';
import {WeaTools} from 'ecCom';
import { WeaTableNew } from 'comsMobx'
const { TableStore } = WeaTableNew;
import Apis from '../apis/Api';
import {message} from 'antd';

export default class Test{
  @observable state_1 = {
    title: "集成测试1",
    data: [],
    sysid: "",
    fields: {},
    flag: "false",
    selectMap: {}
  };
  @observable table = {
    dataKey: ''
  };
  
  @action
  addDataInState1() {
    this.state_1.data.push({
      name: 'test'
    });
  }
  
  @action
  getDatas() {
    WeaTools.callApi('/api/ec/dev/demo/hrm', 'GET', {}).then((result) => {
	  this.table.dataKey =  result.sessionkey;
	  let comsWeaTableStore = new TableStore();
      comsWeaTableStore.getDatas(this.table.dataKey);
    });
  }
  
  test = params => {
    Apis.test(params).then(result => {
      this.state_1 = {
        ...this.state_1,
        data: result.data,
        sysid: result.sysid,
        selectMap: result.selectMap
      };
    }).catch(
      error => {
        message.error(error)
      }
    )
  }
  
  saveTest = params => {
    Apis.savesetting(params).then(result => {
      if (result.flag != "false") {
        message.success('保存成功', 3);
      }else{
        message.error('保存失败')
      }
      this.state_1 = {
        ...this.state_1,
        flag: result.flag,
        data: result.data
      }
    }).catch(
      error => {
        message.error(error)
      }
    )
  }
  
  setFields = (fields) => {
    let newFields = {...this.state_1.fields};
    for (let name in fields) {
      newFields[name] = fields[name].value
    }
    this.state_1.fields = newFields;
  }
}